import httpRequest from './hrequest'
const Request = new httpRequest()

// 请求拦截器
Request.interceptors.request((request: any) => {
 /* console.log('请求前:',request.header,request.header["content-type"])
  if (request.header["content-type"]) {
    request.header['content-type'] = request.header.contentType
    delete request.header["content-type"]
	console.log('删除contentType:',request.header)
  } */
  //console.log("请求方法",request.method);
  if (request.method === 'POST') {
	  request.header.token=uni.getStorageSync('token');  //请求前带上token
  }
  
  if (request.method === 'GET') {
    //request.data = JSON.stringify(request.data)
	delete request.header.token;
	let reqData=JSON.stringify(request.data)
	if((reqData!="{}")){
		//console.log("请求有参数",reqData)
		request.url = request.url + '?' +reqData
		//console.log("request.url========》",request.url,"request========》",request)
	}
  }
  return request
})

// 响应拦截器
Request.interceptors.response((response: any) => {
  //const token = uni.getStorageSync('token')
  // if (response.data.code === 403) {
  //   uni.showToast({
  //     title: token ? '请重新登录' : '请先登录',
  //     icon: 'none',
  //     duration: 2000,
  //   })
  //   uni.removeStorageSync('token')
  //   uni.removeStorageSync('userInfo')
  // }
  return response
})



// 设置默认配置
Request.setConfig((config: any) => {
  config.baseURL = "https://www.qq.com"
  //config.header.token=uni.getStorageSync('token'); 
  /* 
  if (uni.getStorageSync('token')) {
    config.header['Authorization'] = 'Bearer ' + uni.getStorageSync('token')
  } */
  return config
})

export default Request